<template>
	<view class="container">
		<tui-list-cell :hover="false">
			<view class="tui-img__title">添加开始巡店图片</view>
			<tui-upload fileKeyName='file' :value="value1" :serverUrl="serverUrl" @complete="result" @remove="remove">
			</tui-upload>
		</tui-list-cell>

		<tui-list-cell :hover="false">
			<view class="tui-img__title">添加巡店图片</view>
			<tui-upload :value="value2" @complete="result2" :serverUrl="serverUrl" @remove="remove2"></tui-upload>
		</tui-list-cell>

		<tui-list-cell :hover="false">
			<view class="tui-img__title">添加结束图片</view>
			<tui-upload :value="value3" @complete="result3" :serverUrl="serverUrl" @remove="remove3"></tui-upload>
		</tui-list-cell>
		
		<tui-list-cell :hover="false" padding="0">
			<textarea class="tui-textarea" placeholder="填写巡店备注..." maxlength="200" v-model="remark"></textarea>
		</tui-list-cell>

		<view class="tui-btn-box">
			<button class="tui-button-primary" hover-class="tui-button-hover" type="primary"
				@click="onSubmit()">提交</button>
		</view>


	</view>
</template>

<script>
	import {
		getTaskInfo,
		finishTask
	} from "@/apis/user";
	export default {
		data() {
			return {
				id: 0,
				imageData: [],
				imageData1: [],
				imageData2: [],
				//上传接口地址
				serverUrl: "https://sxsd.zhtingche.com/prod-api/common/upload",
				value: [], //初始化图片
				value2: [], //初始化图片
				value3: [], //初始化图片
				remark:''
			}
		},
		onShow() {
			this.id = this.$yroute.query.id;
		},
		methods: {
			result: function(e) {
				console.log(e)
				this.imageData = e.imgArr;
			},
			result2: function(e) {
				console.log(e)
				this.imageData1 = e.imgArr;
			},
			result3: function(e) {
				console.log(e)
				this.imageData2 = e.imgArr;
			},
			remove: function(e) {
				//移除图片
				console.log(e)
				let index = e.index
			},
			remove2: function(e) {
				//移除图片
				console.log(e)
				let index = e.index
			},
			remove3: function(e) {
				//移除图片
				console.log(e)
				let index = e.index
			},
			onSubmit: function() {
				let that = this;
				const id = this.id;
				if (!id) {
					that.tui.toast("任务不存在！")
					return;
				}
				if (that.imageData.length == 0 || that.imageData1.length == 0 ||
					that.imageData2.length == 0) {
					that.tui.toast("请上传图片！")
					return;
				}
				let data = {
					taskId: that.id,
					img1: that.imageData.join(","),
					img2: that.imageData1.join(","),
					img3: that.imageData2.join(","),
					remark: that.remark

				};
				finishTask(data).then(res => {
					that.tui.toast("上传成功！")
					this.$yrouter.back();
				}).catch(err => {
					console.log(err)
					that.tui.toast(err.msg)
					
				})
			}
		}
	}
</script>

<style>
	.tui-img__title {
		padding-bottom: 24rpx;
	}

	.tui-check__box {
		padding: 25rpx 30rpx;
	}

	.tui-btn-box {
		padding: 40rpx 50rpx;
		box-sizing: border-box;
	}
	.tui-textarea {
		width: 100%;
		height: 300rpx;
		font-size: 28rpx;
		padding: 20rpx 30rpx;
		box-sizing: border-box;
		background-color: #fff;
	}
</style>
